<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
    <style>
      #app {
        font-family: Avenir, Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <h2>{{person}}</h2>
      <button @click="deleteName">删除派大星</button>
      <button @click="changeName">把派大星改成蟹老板</button>
      <button @click="addName">增加一个蟹老板</button>
    </div>
    <script>
      Vue.config.productionTip = false;
      //实例化Vue
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            person: ["海绵宝宝", "派大星", "章鱼哥", "珊迪"],
          };
        },
        methods: {
          deleteName() {
            // 不能直接修改
            // this.person[2] = "蟹老板";

            // 需要使用数组的方法修改
            this.person=this.person.filter(item=>{
              return item!=="派大星"
            })
          },
          changeName(){
            // 修改
            this.person.splice(1,1,"蟹老板")
          },
          addName(){
            //增加
            this.person.push("蟹老板")
          }
        },
      });
    </script>
  </body>
</html>
